Imports System
Imports System.Text
Imports System.Collections.Generic
Imports Microsoft.VisualStudio.TestTools.UnitTesting
Imports DotnetIndia.StockQuotes
Imports System.Drawing

<TestClass()> Public Class StockComponentTest

#Region "Additional test attributes"
    '
    ' You can use the following additional attributes as you write your tests:
    '
    ' Use ClassInitialize to run code before running the first test in the class
    ' <ClassInitialize()> Public Shared Sub MyClassInitialize(ByVal testContext As TestContext)
    ' End Sub
    '
    ' Use ClassCleanup to run code after all tests in a class have run
    ' <ClassCleanup()> Public Shared Sub MyClassCleanup()
    ' End Sub
    '
    ' Use TestInitialize to run code before running each test
    ' <TestInitialize()> Public Sub MyTestInitialize()
    ' End Sub
    '
    ' Use TestCleanup to run code after each test has run
    ' <TestCleanup()> Public Sub MyTestCleanup()
    ' End Sub
    '
#End Region

    <TestMethod()> Public Sub TestStockPriceSuccess()
        ' Normal Flow and check the Stock Rate
        Dim StockRateProvider As New Yahoo.StockQuotes
        Dim IncomingData As StockQuoteData
        IncomingData = StockRateProvider.GetStockQuote("polaris.ns")
        Assert.IsTrue(IncomingData.StockRate > 0)
    End Sub

    <TestMethod()> _
    <ExpectedException(GetType(InvalidSymbolException), "An Invalid Stock Symbol was passed")> _
    Public Sub TestStockPriceFailure()
        ' Send in an Invalid Symbol to see if we can catch it
        Dim StockRateProvider As New Yahoo.StockQuotes
        Dim IncomingData As StockQuoteData
        'Changed the stock symbol as polas gets mapped to polas.bs now in yahoo search
        IncomingData = StockRateProvider.GetStockQuote("polas.ns")
    End Sub

    <TestMethod()> Public Sub TestStockPriceSuccesswithExchange()
        ' Normal Flow and check the Stock Rate with Exchage as NSE
        Dim StockRateProvider As New Yahoo.StockQuotes
        Dim IncomingData As StockQuoteData
        IncomingData = StockRateProvider.GetStockQuote("polaris", IndiaExchange.NSE)
        Assert.IsTrue(IncomingData.StockRate > 0)
    End Sub


    <TestMethod()> Public Sub TestStockPriceBSE()
        ' Normal Flow and check the Stock Rate with Exchange as BSE
        Dim StockRateProvider As New Yahoo.StockQuotes
        Dim IncomingData As StockQuoteData
        IncomingData = StockRateProvider.GetStockQuote("532254", IndiaExchange.BSE)
        Assert.IsTrue(IncomingData.StockRate > 0)
    End Sub

    <TestMethod()> Public Sub TestStockChart()
        ' Normal Flow and check the Stock Chart
        Dim StockRateProvider As New Yahoo.StockQuotes
        Dim IncomingData As Image
        IncomingData = StockRateProvider.GetStockCharts("polaris.ns", ChartDurationType.OneDay)
        Assert.IsNotNull(IncomingData)
        IncomingData.Save("c:\test.png", Imaging.ImageFormat.Png)
    End Sub
End Class
